package com.lanou3g.code0420;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/4/20;
 * Otherwise, I don't know who created it either
 */

public class ReadThread extends Thread {
    private Socket socket;

    public ReadThread(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        BufferedReader reader = null;
        try {
            InputStream is = socket.getInputStream();
            reader = new BufferedReader(
                            new InputStreamReader(is));
            String line = "";
            while ((line = reader.readLine()) != null){
                System.out.println(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
